﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BDSim
{
    public class MonitorReceiverDataProvider : BDSimDataProvider
    {
        private MonitorReceiver _Parent;

        public MonitorReceiver Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        #region 命令定义
        public override void DefineCommand()
        {
            MenuCommand mcdFreSet = new MenuCommand() { Header = "接收频率设置" };
            mcdFreSet.DefineExcuteCommand(mcdFreSet_Execute, mcdFreSet_CanExecute);
            MenuCommandList.Add(mcdFreSet);

            MenuCommand ClockReport = new MenuCommand() { Header = "生成报告" };
            ClockReport.DefineExcuteCommand(ClockReport_Execute, ClockReport_CanExecute);
            MenuCommand ClockFigure = new MenuCommand() { Header = "生成图表" };
            ClockFigure.DefineExcuteCommand(ClockFigure_Execute, ClockFigure_CanExecute);
            MenuCommand ClockDataExport = new MenuCommand() { Header = "钟差数据" };
            ClockDataExport.SubMenuCommandList.Add(ClockReport);
            ClockDataExport.SubMenuCommandList.Add(ClockFigure);
            MenuCommandList.Add(ClockDataExport);

            MenuCommand ObsDataReport = new MenuCommand() { Header = "观测数据报告" };
            ObsDataReport.DefineExcuteCommand(ObsDataReport_Execute, ObsDataReport_CanExecute);
            MenuCommandList.Add(ObsDataReport);

            //MenuCommand PPositioningDataReport = new MenuCommand() { Header = "定位数据报告" };
            //PPositioningDataReport.DefineExcuteCommand(PPositioningDataReport_Execute, PPositioningDataReport_CanExecute);
            //MenuCommandList.Add(PPositioningDataReport);

            //MenuCommand mcdDelete = new MenuCommand() { Header = "删除" };
            //mcdDelete.DefineExcuteCommand(mcdDelete_Execute, mcdDelete_CanExecute);
            //MenuCommandList.Add(mcdDelete);
        }
        #endregion

        #region 命令执行方法

        #region 接收频率设置
        void mcdFreSet_Execute(object param)
        {
            RecFreSetWnd wndFreSet = new RecFreSetWnd();
            wndFreSet.RecType_Fre = Parent.RecType_Fre;
            if (wndFreSet.ShowDialog() == true)
            {
                if (wndFreSet.One2AllFlag == true)
                {
                    foreach (var GroundSegment in (Parent.Parent as StationBase).Parent.Parent.Parent.SubGroundSegmentList)
                    {
                        foreach (var stationlist in GroundSegment.GroundList)
                        {

                            if (stationlist.Type == EStationType.MonitorStation)
                            {
                                foreach (var station in stationlist.StationList)
                                {
                                    foreach (var rec in (station as MonitorStation).MonitorReceivers)
                                    {
                                        rec.RecType_Fre = wndFreSet.RecType_Fre;
                                    }
                                }
                            }
                        }

                    }
                }
                else
                {
                    Parent.RecType_Fre = wndFreSet.RecType_Fre;
                }
            }
        }

        bool mcdFreSet_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
            }
            return flag;
        }
        #endregion 接收频率设置


        #region 删除命令执行方法
        /// <summary>
        /// 删除接收机功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void mcdDelete_Execute(object param)
        {
            Parent.Parent.MonitorReceivers.Remove(this.Parent);
        }
        /// <summary>
        /// 删除接收机功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool mcdDelete_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
            }
            return flag;
        }

        #endregion

        #region 执行方法模板
        /// <summary>
        /// XXX 功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void XXX_Execute(object param)
        {

        }
        /// <summary>
        /// XXX功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool XXX_CanExecute(object param)
        {
            bool flag = true;

            return flag;
        }
        #endregion

        #region 钟差报告执行方法
        /// <summary>
        /// XXX 功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void ClockReport_Execute(object param)
        {
            DataReportView dataPreview = new DataReportView();
            List<ClkSimData> InterSatClkErrList = new List<ClkSimData>();
            InterSatClkErrList = Parent.Parent.GenerateStepCLKErr();
            dataPreview.InitClkData(InterSatClkErrList, Parent.Name);
            MainDispatcher.DlgAddLayoutDocument(dataPreview, Parent.Name);
        }
        /// <summary>
        /// XXX功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool ClockReport_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.Inited || BDSimObject.GlobalStatus == ESimStatus.Pause)
            {
                flag = true;
            }
            return flag;
        }
        #endregion

        #region 钟差绘图执行方法
        /// <summary>
        /// XXX 功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void ClockFigure_Execute(object param)
        {
            DataFigureView clkFigureView = new DataFigureView();
            List<ClkSimData> SatClkErrList = new List<ClkSimData>();
            SatClkErrList = Parent.Parent.GenerateStepCLKErr();
            clkFigureView.InitClkCharts(Parent.Name, SatClkErrList);
            MainDispatcher.DlgAddLayoutDocument(clkFigureView, Parent.Name + "_钟差图表");
        }
        /// <summary>
        /// XXX功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool ClockFigure_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.Inited || BDSimObject.GlobalStatus == ESimStatus.Pause)
            {
                flag = true;
            }
            return flag;
        }
        #endregion

        #region 观测数据执行方法
        /// <summary>
        /// 监测站观测数据功能命令执行方法
        /// </summary>
        /// <param name="param"></param>
        void ObsDataReport_Execute(object param)
        {
            DataReportView dataPreview = new DataReportView();
            //获取卫星的名称列表
            List<string> remoteNodeNameList = new List<string>();
            foreach (var item in (Parent.Parent.Parent.Parent.Parent.Parent.SegmentColletion[0] as SpaceSegment).AllSatellite)
            {
                remoteNodeNameList.Add(item.Name);
            }

            List<Dictionary<string, List<ObsReceiverOutput>>> allObsSatsDataDic = new List<Dictionary<string, List<ObsReceiverOutput>>>();
            foreach (var onetime in Parent.ALLObsSatsDataDic_ConType)
            {
                foreach (var con in onetime.Keys)
                {
                    allObsSatsDataDic.Add(onetime[con]);
                }
            }
            dataPreview.InitObsData(allObsSatsDataDic, remoteNodeNameList, Parent.Parent.Name + "<" + this.Parent.Name + ">", new double[] { 0, 0, 0 });
            MainDispatcher.DlgAddLayoutDocument(dataPreview, Parent.Parent.Name + "<" + this.Parent.Name + ">" + "_观测数据");
        }
        /// <summary>
        /// 监测站观测数据功能命令可执行控制
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        bool ObsDataReport_CanExecute(object param)
        {
            bool flag = false;
            //当打开了观测数据仿真开关，并且处于初始化完成或暂停状态，卫星数量不等于0，执行此命令
            if (Scenario._IsGenerateObsData &&
                (BDSimObject.GlobalStatus == ESimStatus.Inited || BDSimObject.GlobalStatus == ESimStatus.Pause) &&
                (Parent.Parent.Parent.Parent.Parent.Parent.SegmentColletion[0] as SpaceSegment).AllSatellite.Count > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion

        #endregion
    }
}
